package top.wangjiu.java.jvm.attribute.info;

import top.wangjiu.java.jvm.constantinfo.ConstantPoolInfo;

/**
 *
 */
public class ExeceptionInfo {

    private final short startPc;
    private final short endPc;
    private final short handlerPc; //当字节码在[start_pc, end_pc)区间出现catch_type或子类，则转到handler_pc行继续处理。
    private final short catchType; //当catch_type=0，则任意异常都需转到handler_pc处理

    public ExeceptionInfo(short startPc, short endPc, short handlerPc, short catchType){
        this.startPc = startPc;
        this.endPc = endPc;
        this.handlerPc = handlerPc;
        this.catchType = catchType;
    }

    public String toString(ConstantPoolInfo[] poolInfos){
        return "startPc:"+startPc+", endPc:"+endPc+", handlerPc"+handlerPc +", catchType:"+ (catchType==0?"all":poolInfos[catchType].toString(poolInfos));
    }
}
